package org.mc.sbd.redis.api;

import org.mc.sbd.redis.application.RedisTokenApplicationService;
import org.mc.sbd.redis.infrastructure.dao.RedisTokenCacheDao;
import org.mc.sbd.redis.infrastructure.po.RedisToken;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("rc")
public class RedisCacheController {
    @Resource
    private RedisTokenApplicationService tokenApplicationService;

    @Resource
    private RedisTokenCacheDao redisTokenCacheDao;

    @GetMapping("get/token/{id}")
    public RedisToken getToken(@PathVariable Long id) {
        return redisTokenCacheDao.findById(id);
    }

    @PostMapping("create/token")
    public RedisToken createToken(@RequestBody CreateRedisTokenDto dto) {
        return tokenApplicationService.create(dto.getValue());
    }

    @PostMapping("delete/token/{id}")
    public void createToken(@PathVariable Long id) {
        tokenApplicationService.delete(id);
    }

}
